layui.use(['layer', 'table','laydate','form','tableSelect','tree'], function(){
    var $ = layui.jquery,
        laydate = layui.laydate,
        layer = layui.layer,
        form = layui.form,
        table = layui.table,
        tableSelect = layui.tableSelect,
        tree = layui.tree;

    var index;
    /*全局变量(第一行清单信息)*/
    var salOrdData;
    /*定义所选商品单行数据*/
    var SelectedData
    /*选中所选商品获取数据下标位置*/
    var SelectedIndex;
    /*商品单位*/
    var unit;
    /*根据商品id查询批次表信息*/
    var batchProId;
    /*根据原始单号查询批次表信息*/
    var batchSalOroId;
    /*获取客户编号*/
    var custId;
    /*原始单号*/
    var salRetOrg;
    /*仓库编号*/
    var depotId;
    /*主表数据*/
    var mainTableData;
    /*主表数据下标位置*/
    var mainTableIndex;
    /*商品批次信息*/
    var rowBatch;
    /*最大销售量*/
    /*var maximumSales;*/
    /*商品可退货数量*/
    var singleSales;
    /*定义主表单数组*/
    var confirmDemoAddObj = [];
    /*判断整单退货数据长度*/
    var wholeNum = 0;


    /**********************************日期转换**********************************/
    function dataTime(obj) {
        var date = new Date(obj);
        return date.getFullYear() + "-" + (date.getMonth() + 1) + "-" + date.getDate();
    }
    /*日期转换end*/
    /*endtime*/
    function endtime(obj){ //时间格式0000-00-00
        var bzq=24; //保质期
        // console.log(oddStrObj.proExpirationDate)
        var date = new Date(obj);
        var y = date.getFullYear();
        var m = date.getMonth() + 1+parseInt(bzq); //当前时间加上保质期 当前时间换成其他时间也行
        if(parseInt(m/12)>0){ //大于12个月轮换一年
            y=y+(parseInt(m/12));
            m=m-12*(parseInt(m/12));
        }
        if(m==0){ //无0月,元月及1月
            m=1;
        }
        var d = date.getDate();
        var dateTime = y + "-" + (m < 10 ? ("0" + m) : m) + "-" + (d < 10 ? ("0" + d) : d) +' ';
        return dateTime;
    }
    /*endtime end*/

    /*生产随机单号*/
    function createSalesOrdId(){
        var date = new Date();

        var y = isAddZero(date.getFullYear()); //获取当前年
        var month = isAddZero(date.getMonth() + 1); //获取当前月
        var d = isAddZero(date.getDate()); //获取当前日
        var h = isAddZero(date.getHours());//获取当前小时数(0-23)
        var m = isAddZero(date.getMinutes());//获取当前分钟数(0-59)
        var s = isAddZero(date.getSeconds());//获取当前秒

        return "XT"+y+month+d+h+m+s;
    }
    /*补零操作*/
    function isAddZero(num) {
        return num<10?"0"+num:num;
    }
    /*显示随机单号*/
    $('#RandomSingleNum').val(createSalesOrdId());
    /*生产随机单号end*/


    //选择客户名称(点击input框弹出)
    tableSelect.render({
        elem: '#demo1',//elem属性用来绑定容器的id属性值
        id:'updateCurrent',//绑定id
        table: {
            elem: '#currentTableFilter',
            url:'/showCustomerInfo',
            toolbar:"#toolbarDemo",
            cols: [[
                { field: 'custId', width:80,title:'编号', align: "center"},
                { field: 'custName',width:120, title: '客户名称', align: "center"},
                { field: 'custPhone',width:120, title: '联系电话', align: "center"},
                { field: 'custAddress',width:120, title: '联系地址', align: "center"},
                { field: 'custTypeId', width:120,title: '客户类型', align: "center"},
                { field: '', width:120,title: '所属地区', align: "center"},
                { title: '操作', minWidth: 100, toolbar: '#currentTableBar', align: "center"}
            ]]
        },
        done: function (elem, data) {
            var NEWJSON = [];
            layui.each(data.data, function (index, item) {
                NEWJSON.push(item.custName);
                custId = item.custId;
                $("#custId").val(custId)
            })

            elem.val(NEWJSON.join(","));
            //获取选中内容
        },
    });



    /*表内部按钮*/
    table.on('tool(updateCurrent)',function (obj) {
        alert(custId);
    })

    /*表上方按钮*/
    table.on('toolbar(updateCurrent)',function (obj) {
        alert(1);
    })

    //选择日期
    laydate.render({
        elem:"#sellData", //绑定id
        format: 'yyyy-MM-dd', //指定时间格式
        value: new Date(), // 指定值
    });


    var info = [];
    if(parent.billList != undefined){
        info = JSON.parse(parent.billList)
    }

    //表单数据(主表单商品信息)
    table.render({
        elem: '#currentTableId',
        data:info,
        totalRow:true,
        toolbar: '#toolbarDemo2',
        cols: [[
            {field: 'orproId', width: 90, title: '商品编号', totalRowText:'合计：'},
            {field: 'orproName', width: 120, title: '商品名称',align: "center"},
            {field: 'orsalOrdDescUnit', width: 70, title: '单位',align: "center"},
            {field: 'orproSize', width: 100, title: '产品规格',align: "center"},
            {field: 'proPostil', width: 105, title: '批准文号'},
            {field: 'orsalOrdDescProBatchNum', width:105, title: '产品批号'},
            {field: 'orsalOrdDescProStartDate', width: 110, title: '生产日期',
                templet:function (obj) {
                    return dataTime(obj.orsalOrdDescProStartDate);
                }},
            {field: 'orsalOrdDescProValidityDate', width: 110, title: '有效期至',
                templet:function (obj) {
                    return endtime(obj.orsalOrdDescProStartDate);
                }},
            {field: 'orsalOrdDescProPrice',width: 70, title: '单价',align: "center"},
            {field: 'orsalRetDescProNum', width: 72,title: '数量',align: "center", totalRow: true,
                templet: function(data) {
                    return Math.round(data.orsalRetDescProNum)
                }
            },
            {field: 'depositRate', width: 90, title: '折扣率',align: "center",
                templet:function (obj) {
                    return 1;
                }},
            {title: '总金额',
                width: 90,align: "center",
                totalRowText: "<span class=totalMoneyes></span>",
                templet: function(data) {
                    return Math.round(data.orsalOrdDescProPrice * data.orsalRetDescProNum * 1);
                }},
            {field: 'orsalOrdDescManufacturer', width: 140, title: '生产产商'},
        ]],

        /*计算总金额*/
        done: function(data) {
            var mores = 0;
            var obj = data.data;
            for (var i in obj) {
                mores += obj[i].orsalOrdDescProPrice * obj[i].orsalRetDescProNum * 1;
            }
            $('#salRetRefunded').val(mores);
            $('#salRetRealRefund').val(mores);
            $('.totalMoneyes').html("￥" + Math.round(mores));
            /*表格第一行数据*/
            mainTableData= data.data[0];

            /*下标默认为0*/
            mainTableIndex = 0;

            $('#currentTableId~div tr[data-index=0]').addClass('layui-bg-green');

            addDisabled();
        },
        limits: [10, 15, 20, 25, 50, 100],
        limit: 15,
        page: true,
        skin: 'line'
    });

    /*下拉列表仓库*/
    $.ajax({
        type:"GET",
        url:"/showStorehouse",
        success:function(deportList){
            var jsonList = JSON.parse(deportList);
            var unitObj = $('#deport');
            if( 0 != jsonList.length ){ //后台传回来的select选项
                for(var i=0;i<jsonList.length;i++){
                    //遍历后台传回的结果，一项项往select中添加option
                    unitObj.append(new Option(jsonList[i].depotName,jsonList[i].depotId));
                }
                for ( var i in info ) {
                    unitObj.val(info[i].ordepotId);
                }
                /*渲染至select*/
                form.render('select');
            }
        }
    })

    /*下拉框经办人*/
    $.ajax({
        type:"GET",
        url:"/showEmpName",
        dataType:"json",
        success:function (obj) {
            $.each(obj.data,function (index,item) {
                $('#empName').append(new Option(item.empName,item.empId))
            })
            form.render('select');
        }
    })


    /*双击查询商品详情信息(主表单)*/
    /*table.on('rowDouble(mportExpor)', function(obj){
        var row = obj.data;
        updateCommodity(row);
    });*/

    //没选择客户时无法添加商品
    table.on('toolbar(mportExpor)', function (obj) {
        if(custId != null) {
            switch (obj.event) {
                /*商品添加*/
                case"add":
                    /*根据客户编号执行表格重载*/
                    table.reload('allAttTable', {
                        url: '/showReturnedPurchase',
                        where: {
                            custId: custId,
                            salOrdId:salRetOrg,
                        }
                    });

                    /*原始单号*/
                    $.ajax({
                        type:"GET",
                        url:"/showSaleCustId/"+custId,
                        dataType:"json",
                        success:function (obj) {
                            $.each(obj.data,function (index,item) {
                                $('#salRetOriginalNum').append(new Option(item.salOrdId,item.salOrdId))
                            })
                            form.render('select');
                        }
                    });
                    /*下拉框刷新*/
                    $('#salRetOriginalNum').html(new Option('请选择',''));

                    /*调用弹窗*/
                    addCommodity();

                    /*表格刷新(待)*/

                    break;

                /*整单退货*/
                case"returnedPurchase":
                    /*removeGoods();*/
                    break;

                /*商品修改*/
                case"update":
                    /*主表修改数量*/

                    updateCommodity(mainTableData);
                    break;

                /*删除*/
                case"delete":
                    deleteCommodity();
                    break;
            }
        }else {
            layer.msg("未选择客户！")
        }

    })

    /*新增商品弹出层*/
    function addCommodity(){
        layer.open({
            type: 1,
            title: '<h2 style="color: black;font-weight: bold;">增加商品(销售退货)<h2>',
            shade: 0.2,
            maxmin:true,
            shadeClose: true,
            area: ['100%', '100%'],
            content: $('#CommodityAddPage')
        });
    }

    /*整单退货弹出层*/
    function removeGoods(){
        layer.open({
            type: 1,
            title: '<h2 style="color: black;font-weight: bold;">整单退货<h2>',
            shade: 0.2,
            maxmin:true,
            shadeClose: true,
            area: ['100%', '100%'],
            content: $('#removeGoods')
        });
    }

    /***************************退出弹窗按钮***************************/

    $('.exitBut').click(function () {
        layer.close(index);
    });
    /*点击商品信息（库存调拨）弹窗的取消按钮关闭弹窗*/
    /*function exit() {
        layer.close(index);
    }*/
    /*修改商品弹出层*/
    function updateCommodity(data){
        index=layer.open({
            type: 1,
            title: '<h2 style="color: black;font-weight: bold;">商品信息<h2>',
            scrollbar: false,
            area: ['660px', '550px'],/*宽高*/
            /*btn: ['确定','退出'],
            btnAlign: 'c',*/
            content: $('#updateCommodityDiv'),
            /*获取点击表单数据*/
            success:function(){
                form.val('commodityInfo',data)
            },

            /*cancel:function () {
                $("#CommodityAddPage")[0].reset();
            }*/
            /*end: function () {
                addCommodity
            }*/
            /*end: function() {undefined
                //刷新页面,
                location.reload();
            }*/
        });
    }

    /*删除商品弹出层*/
    function deleteCommodity(){
        layer.open({
            type: 1,
            title: '<h2 style="color: black;font-weight: bold;">删除商品<h2>',
            area: ['25%', '40%'],
            content: $('#deleteCommodityDiv'),
            scrollbar: false,
            btn: ['是', '否'],
            btn1: function (index) {
                /*获取选中数据在表单中的下标位置并删除*/
                confirmDemoAddObj.splice(mainTableIndex, 1);

                /*清空选中删除数据*/
                mainTableData = null;

                table.reload("currentTableId", {
                    data: confirmDemoAddObj // 将新数据重新载入表格
                })

                layer.close(index);
            },
            btn2: function () {
            }
        })
    }

    /************添加商品详情页面************/

    /*商品清单*/
    table.render({
        elem: '#commoditydemo8',
        url: '/showReturnedPurchase',
        height:400,
        width:652,
        id:'allAttTable',/*执行重载id*/
        cols: [[
            {field: 'salOrdId', width: 110, title: '原始单号', sort: true,fixed:'left',templet:function (data) {
                return data.saleOrder.salOrdId;
                }},
            {field: 'productId', width: 110, title: '商品编号', sort: true},
            {field: 'salOrdDescProName', width: 110, title: '商品名称'},
            {field: 'salOrdDescUnit', width: 60, title: '单位',align: "center"},
            {field: 'proSize', width: 80, title: '规格',align: "center",templet:function (data) {
                    return data.productInfo.proSize;
                }},
            {field: 'salOrdDescProPrice',width: 90, title: '预设售价',align: "center"},
            {field: 'salOrdDescProNum', width: 80, title: '销售量',align: "center"},
            {field: 'salOrdDescManufacturer', width: 114, title: '生产厂商',align: "center"},
        ]],done: function (obj) {
            /*表格第一行数据*/
            salOrdData= obj.data[0];
            $('#commoditydemo8~div tr[data-index=0]').addClass('layui-bg-green');
        }
    });

    /*点击加入所选商品时填充数据*/
    $(document).on('click','#dataSearchBtn',function () {
        /*数量为1*/
        $('#commodityNum').val(1);
        /*区分弹窗(商品清单)*/
        $('#updateCommodityNone').text(1);

        /*根据商品id查询批次表信息*/
        batchProId = salOrdData.productId;
        /*根据原始单号查询批次表信息*/
        batchSalOroId = salOrdData.salOrdId;

        /*封装起来多次调用批次表*/
        batchForm();

        updateCommodity(salOrdData);

        /*根据id获取至弹窗*/

        /*规格型号*/
        $('#proSize').val(salOrdData.productInfo.proSize);
        /*销售量*/
        $('#salOrdDescProNum').val(salOrdData.salOrdDescProNum + salOrdData.salOrdDescUnit);
        $('#salOrdDescProNums').html(salOrdData.salOrdDescProNum+ salOrdData.salOrdDescUnit);
        /*批准文号*/
        $('#proPostil').val(salOrdData.productInfo.proPostil);
        /*产品批号*/
        $('#salOrdDescProBatchNum').val(salOrdData.salOrdDescProBatchNum);
        /*生产日期*/
        $('#salOrdDescProStartDate').val(dataTime(salOrdData.salOrdDescProStartDate));
        /*有效期至*/
        $('#salOrdDescProValidityDate').html(endtime(salOrdData.salOrdDescProStartDate));
        /*总金额*/
        $('#aggregateAmount').html(0);

    });


    /*表格重载(商品清单模糊查询)*/
    $(document).on('keyup','#fuzzyIdName',function () {
        table.reload('allAttTable',{
            url: '/showReturnedPurchase',
            where:{
                productId:$(this).val(),
                salOrdDescProName:$(this).val(),
                custId:custId,
                salOrdId:salRetOrg,
            }
        });
    });


    /*原始单号查询商品清单*/
    form.on('select(salRetOriginalNum)',function (obj) {
        salRetOrg = obj.value;
        table.reload('allAttTable',{
            url: '/showReturnedPurchase',
            where:{
                productId:$(this).val(),
                salOrdDescProName:$(this).val(),
                custId:custId,
                salOrdId:salRetOrg,
            }
        });
        /*选完原始单号清空模糊查询输入内容*/
        $('#fuzzyIdName').val(null);
    })

    /*商品清单(双击查询)*/
    table.on('rowDouble(commoditydemo8)', function(obj){
        /*每次点击商品清单数量为1*/
        $('#commodityNum').val(1);
        /*单位*/
        unit = salOrdData.salOrdDescUnit;
        /*商品ID*/
        batchProId = salOrdData.productId;
        /*根据原始单号查询批次表信息*/
        batchSalOroId = salOrdData.salOrdId;

        /*封装起来多次调用批次表*/
        batchForm();

        /*区分弹窗(商品清单)*/
        $('#updateCommodityNone').text(1);

        /*根据id获取至弹窗(2)*/
        /*规格型号*/
        $('#proSize').val(salOrdData.productInfo.proSize);
        /*销售量*/
        $('#salOrdDescProNum').val(salOrdData.salOrdDescProNum + salOrdData.salOrdDescUnit);
        $('#salOrdDescProNums').html(salOrdData.salOrdDescProNum+ salOrdData.salOrdDescUnit);
        /*批准文号*/
        $('#proPostil').val(salOrdData.productInfo.proPostil);
        /*产品批号*/
        $('#salOrdDescProBatchNum').val(salOrdData.salOrdDescProBatchNum);
        /*生产日期*/
        $('#salOrdDescProStartDate').val(dataTime(salOrdData.salOrdDescProStartDate));
        /*有效期至*/
        $('#salOrdDescProValidityDate').html(endtime(salOrdData.salOrdDescProStartDate));

        /*总金额*/
        $('#aggregateAmount').html(0);

        /*弹窗*/
        updateCommodity(salOrdData);
    });


    /*根据单价,数量,折扣率计算商品总价*/
    /*数量框*/
    $('#commodityNum').on('keyup',function () {
        /*获取区分弹窗*/
        var updateCommodityNone = $('#updateCommodityNone').text();
        if (updateCommodityNone==1){/*商品可退货数量*/
            singleSales = salOrdData.salOrdDescProNum - salOrdData.salRetDescProNum;
            singleSales = rowBatch.salOrdDescProNum;
        }else if (updateCommodityNone==2){
            singleSales = SelectedData.salRetDescProNum;
            singleSales = rowBatch.salOrdDescProNum;
        }

        /*console.log(singleSales)*/
        if($(this).val() > singleSales){
            returnNumDeficiency();
            /*弹出数量不足后输入最大数量*/
            $('#commodityNum').val(singleSales);
        }

        /*****************动态获取所选商品可退货数量*****************/
        /*/!*判断所选商品数组中是否有值*!/
        if (comBatchArrayObj[0] != null){
            /!*循环所选商品所有数据*!/
            for (var i in comBatchArrayObj){
                if(comBatchArrayObj[i].productId == salOrdData.productId&&
                    comBatchArrayObj[i].salOrdDescProBatchNum==salOrdData.salOrdDescProBatchNum&&
                    comBatchArrayObj[i].salOrdDescManufacturer==salOrdData.salOrdDescManufacturer&&
                    comBatchArrayObj[i].salOrdId==salOrdData.salOrdId){

                    singleSales = comBatchArrayObj[i].salOrdDescProNum;
                }

            }
            console.log(singleSales)
        }*/

        $('#aggregateAmount').html($('#salOrdDescProPrice').val()*$(this).val()*$('#depositRate').val());

    });

    function batchForm() {
        /*商品批次信息*/
        table.render({
            elem: '#commoditydemo',
            url:"/showCommodityBatch/"+ batchProId + "/" + batchSalOroId,
            cols: [[
                {field: 'productId', width: 90, title: '商品编号'},
                {field: 'salOrdDescProName', width: 90, title: '商品名称'},
                {field: 'salOrdDate', width: 90, title: '销售日期',templet:function (data) {
                        return dataTime(data.saleOrder.salOrdDate);
                    }},
                {field: 'salOrdDescProNum', width: 90, title: '可退数量',align: "center"},
                {field: 'salOrdDescProBatchNum', Width: 125, title: '产品批号'},
                {field: 'salOrdDescProStartDate', width: 90, title: '生产日期',templet:function (data) {
                        return dataTime(data.salOrdDescProStartDate);
                    }},
                {field: '', width: 90, title: '有效期至',templet:function (data) {
                        return endtime(data.salOrdDescProStartDate);
                    }},
            ]],done: function (obj) {
                /*console.log(obj.data)*/
                /*默认获取第一行数据*/
                rowBatch = obj.data[0];
                /*singleSales = rowBatch.salOrdDescProNum;*/
                /*默认选中第一行样式*/
                $('#commoditydemo~div tr[data-index=0]').addClass('layui-bg-green');
            }
        });

        /*商品退货历史*/
        table.render({
            elem: '#commoditydemoHistory',
            url:"/showReturnHistory/"+ batchProId + "/" + batchSalOroId,
            cols: [[
                {field: 'productId', width: 90, title: '退货商品编号',templet:function (data) {
                        return data.saleReturnDesc.productId;
                    }},
                {field: 'salRetDescProName', width: 90, title: '退货商品名称',templet:function (data) {
                        return data.saleReturnDesc.salRetDescProName;
                    }},
                {field: 'salRetDate', width: 90, title: '商品退货日期',templet:function (data) {
                        return dataTime(data.salRetDate);
                    }},
                {field: 'salRetDescNum', width: 90, title: '退货数量',align: "center",templet:function (data) {
                        return data.saleReturnDesc.salRetDescNum;
                    }},
                {field: 'salRetDescproBatchNum', Width: 125, title: '产品批号',templet:function (data) {
                        return data.saleReturnDesc.salRetDescproBatchNum;
                    }},
                {field: 'salRetDescProStartDate', width: 90, title: '生产日期',templet:function (data) {
                        return dataTime(data.saleReturnDesc.salRetDescProStartDate);
                    }},
                {field: '', width: 90, title: '有效期至',templet:function (data) {
                        return endtime(data.saleReturnDesc.salRetDescProStartDate);
                    }},
            ]],done: function (obj) {
                /*默认选中第一行样式*/
                $('#commoditydemoHistory~div tr[data-index=0]').addClass('layui-bg-green');
            }
        });
    }


    /*单击商品批次改变弹窗数据*/
    table.on('row(commoditydemo)',function (obj) {
        rowBatch = obj.data;
        singleSales = rowBatch.salOrdDescProNum;
        obj.tr.addClass('layui-bg-green').siblings().removeClass('layui-bg-green');
        /*当前库存，产品批号，有效期，*/
        $('#salOrdDescProNum').val(rowBatch.salOrdDescProNum + unit);
        $('#salOrdDescProNums').html(rowBatch.salOrdDescProNum + unit);

        $('#salOrdDescProBatchNum').val(rowBatch.salOrdDescProBatchNum);

        $('#salOrdDescProStartDate').val(dataTime(rowBatch.salOrdDescProStartDate));
        $('#salOrdDescProValidityDate').html(endtime(rowBatch.salOrdDescProStartDate));

        /*总金额*/
        $('#aggregateAmount').html($('#salOrdDescProPrice').val()*$('#commodityNum').val()*$('#depositRate').val());
    });

    /****************************将数据传递至所选商品表****************************/
    /*定义数组*/
    var comBatchArrayObj = [];

    /*点击确认将数据传递给所选商品列表*/
    $(document).on('click','#comBatchSub',function () {
        /*获取区分弹窗*/
        var updateCommodityNone = $('#updateCommodityNone').text();
        /*区分隐藏域*/
        if (updateCommodityNone == 1){
            /*传递数据至所选商品表*/
            var data = {
                /*商品编号*/
                productId:salOrdData.productId,
                /*商品名称*/
                salOrdDescProName:salOrdData.salOrdDescProName,
                /*商品单位*/
                salOrdDescUnit:salOrdData.salOrdDescUnit,
                /*销售订单编号(原始单号)*/
                salOrdId:salOrdData.saleOrder.salOrdId,
                /*仓库编号*/
                depotId:salOrdData.saleOrder.depotId,
                /*产品规格*/
                proSize:$('#proSize').val(),
                /*批准文号*/
                proPostil:$('#proPostil').val(),
                /*折扣率*/
                depositRate:$('#depositRate').val(),
                /*生产厂商*/
                salOrdDescManufacturer:$('#salOrdDescManufacturer').val(),
                /*商品单价*/
                salOrdDescProPrice:$('#salOrdDescProPrice').val(),
                /*商品数量*/
                salOrdDescProNum:eval($('#commodityNum').val()),
                /*产品批号*/
                salOrdDescProBatchNum:$('#salOrdDescProBatchNum').val(),
                /*生产日期*/
                salOrdDescProStartDate:$('#salOrdDescProStartDate').val(),
                /*有效期至*/
                salOrdDescProValidityDate:$('#salOrdDescProValidityDate').html(),
                /*退货数量*/
                salRetDescProNum:salOrdData.salOrdDescProNum - salOrdData.salRetDescProNum,
            }

            var ii = 1;
            /*循环*/
            for(var i in comBatchArrayObj){
                /*判断原始单号，生产日期，产品批号，生产厂商是否相同(相同则累加)*/
                /*判断输入数量是否是否超过退货数量，是则显示最大退货数量，否则累加*/
                if(eval(comBatchArrayObj[i].salOrdDescProStartDate)==eval(data.salOrdDescProStartDate)&&
                    comBatchArrayObj[i].salOrdDescProBatchNum==data.salOrdDescProBatchNum&&
                    comBatchArrayObj[i].salOrdDescManufacturer==data.salOrdDescManufacturer&&
                    comBatchArrayObj[i].salOrdId==data.salOrdId
                    &&comBatchArrayObj[i].salOrdDescProNum > singleSales){
                    comBatchArrayObj[i].salOrdDescProNum = singleSales;
                    ii = 0;
                }
                /*累加到最大退货数量停止累加*/
                else if(comBatchArrayObj[i].productId==data.productId &&
                    comBatchArrayObj[i].salOrdDescProBatchNum==data.salOrdDescProBatchNum &&
                    comBatchArrayObj[i].salOrdId==data.salOrdId) {
                    if(comBatchArrayObj[i].salOrdDescProNum >= singleSales || (comBatchArrayObj[i].salOrdDescProNum + data.salOrdDescProNum) > singleSales){
                        comBatchArrayObj[i].salOrdDescProNum = singleSales;
                        returnNumDeficiency();
                        ii = 0;
                    }else {
                        /*累加商品数量(eval转换为int类型)*/
                        comBatchArrayObj[i].salOrdDescProNum = eval(comBatchArrayObj[i].salOrdDescProNum) + eval($('#commodityNum').val());
                        ii = 0;
                    }
                }
            }

            if(ii == 1){
                comBatchArrayObj.push(data);
            }

            /*修改所选商品弹窗*/
        }else if (updateCommodityNone==2){
            /*comBatchArrayObj[]*/
            /*传递数据至所选商品表*/
            var data = {
                /*商品编号*/
                productId:SelectedData.productId,
                /*商品名称*/
                salOrdDescProName:SelectedData.salOrdDescProName,
                /*商品单位*/
                salOrdDescUnit:SelectedData.salOrdDescUnit,
                /*销售订单编号(原始单号)*/
                salOrdId:SelectedData.salOrdId,
                /*仓库编号*/
                depotId:salOrdData.saleOrder.depotId,
                /*产品规格*/
                proSize:$('#proSize').val(),
                /*批准文号*/
                proPostil:$('#proPostil').val(),
                /*折扣率*/
                depositRate:$('#depositRate').val(),
                /*生产厂商*/
                salOrdDescManufacturer:$('#salOrdDescManufacturer').val(),
                /*商品单价*/
                salOrdDescProPrice:$('#salOrdDescProPrice').val(),
                /*商品数量*/
                salOrdDescProNum:eval($('#commodityNum').val()),
                /*产品批号*/
                salOrdDescProBatchNum:$('#salOrdDescProBatchNum').val(),
                /*生产日期*/
                salOrdDescProStartDate:$('#salOrdDescProStartDate').val(),
                /*有效期至*/
                salOrdDescProValidityDate:$('#salOrdDescProValidityDate').html(),
                /*退货数量*/
                salRetDescProNum:salOrdData.salOrdDescProNum - salOrdData.salRetDescProNum,
            }

            var ii = 1;
            /*循环*/
            for(var i in comBatchArrayObj){
                /*生产日期，生产厂商，原始单号*/
                if(eval(comBatchArrayObj[i].salOrdDescProStartDate)==eval(data.salOrdDescProStartDate)&&
                    comBatchArrayObj[i].salOrdDescManufacturer==data.salOrdDescManufacturer&&
                    comBatchArrayObj[i].salOrdId==data.salOrdId){
                    /*替换商品数量(eval转换为int类型)*/
                    comBatchArrayObj[i].salOrdDescProNum = eval($('#commodityNum').val());
                    /*修改无需累加*/
                    ii = 0;
                }
            }
            if(ii == 1){
                comBatchArrayObj.push(data);
            }
        }

        /*表格重载*/
        table.reload('commoditydemoAdd', {
            data:comBatchArrayObj
        });
        /*单击确定时关闭弹窗*/
        layer.close(index);
    });

    /*点击所选商品修改按钮*/
    $(document).on('click','#updataDemoAddBut',function () {
        /*数量*/
        $('#commodityNum').val(SelectedData.salOrdDescProNum);
        /*判断所选商品是否有数据*/
        if (comBatchArrayObj[0] != null){
            /*区分弹窗(数量修改而不是累加)*/
            $('#updateCommodityNone').text(2);

            /*根据商品id查询批次表信息*/
            batchProId = SelectedData.productId;
            /*根据原始单号查询批次表信息*/
            batchSalOroId = SelectedData.salOrdId;

            /*封装起来多次调用批次表*/
            batchForm();
            updateCommodity(SelectedData);

            /*根据id获取至弹窗(3)*/
            /*规格型号*/
            $('#proSize').val(SelectedData.proSize);
            /*销售量*/
            $('#salOrdDescProNum').val(SelectedData.salOrdDescProNum + SelectedData.salOrdDescUnit);
            $('#salOrdDescProNums').html(SelectedData.salOrdDescProNum+ SelectedData.salOrdDescUnit);
            /*批准文号*/
            $('#proPostil').val(SelectedData.proPostil);
            /*产品批号*/
            $('#salOrdDescProBatchNum').val(SelectedData.salOrdDescProBatchNum);
            /*生产日期*/
            $('#salOrdDescProStartDate').val(dataTime(SelectedData.salOrdDescProStartDate));
            /*有效期至*/
            $('#salOrdDescProValidityDate').html(endtime(SelectedData.salOrdDescProStartDate));
        }else {
            layer.msg('未添加商品!')
        }

    })

    /*双击查询商品详情信息(所选商品详情列表)*/
    table.on('rowDouble(commoditydemoAdd)', function(obj){
        /*数量*/
        $('#commodityNum').val(SelectedData.salOrdDescProNum);
        /*区分弹窗(数量修改而不是累加)*/
        $('#updateCommodityNone').text(2);
        /*修改弹窗*/
        updateCommodity(obj.data);

        /*根据商品id查询批次表信息*/
        batchProId = SelectedData.productId;
        /*根据原始单号查询批次表信息*/
        batchSalOroId = SelectedData.salOrdId;

        /*封装起来多次调用批次表*/
        batchForm();

        /*规格型号*/
        $('#proSize').val(SelectedData.proSize);
        /*销售量*/
        $('#salOrdDescProNum').val(SelectedData.salOrdDescProNum + SelectedData.salOrdDescUnit);
        $('#salOrdDescProNums').html(SelectedData.salOrdDescProNum+ SelectedData.salOrdDescUnit);
        /*批准文号*/
        $('#proPostil').val(SelectedData.proPostil);
        /*产品批号*/
        $('#salOrdDescProBatchNum').val(SelectedData.salOrdDescProBatchNum);
        /*生产日期*/
        $('#salOrdDescProStartDate').val(dataTime(SelectedData.salOrdDescProStartDate));
        /*有效期至*/
        $('#salOrdDescProValidityDate').html(endtime(SelectedData.salOrdDescProStartDate));
    });

    /*所选商品列表*/
    table.render({
        elem: '#commoditydemoAdd',
        data:[],
        height:400,
        width:600,
        cols: [[
            {field: 'salOrdId', width: 90, title: '原始单号', fixed:'left'},
            {field: 'salOrdDescProName', width: 90, title: '商品名称'},
            {field: 'salOrdDescUnit', width: 60, title: '单位',align: "center"},
            {field: 'salOrdDescProPrice', width: 60, title: '单价',align: "center"},
            {field: 'salOrdDescProNum', width:60, title: '数量',align: "center"},
            {field: '', width: 72, title: '总金额',align: "center",templet:function (data) {
                    return data.salOrdDescProPrice * data.salOrdDescProNum * data.depositRate
                }},
            {field: 'salOrdDescProBatchNum', width: 90, title: '产品批号'},
            {field: 'salOrdDescProStartDate', width: 90, title: '生产日期'},
            {field: 'salOrdDescProValidityDate', width: 90, title: '有效期至', templet:function (data) {
                    return endtime(data.salOrdDescProStartDate);
                }},
        ]],done: function (obj) {
            /*表默认第一条数据*/
            SelectedData = obj.data[0];
            /*下标默认为0*/
            SelectedIndex = 0;
            /*默认选中第一行样式*/
            $('#commoditydemoAdd~div tr[data-index=0]').addClass('layui-bg-green');
        }

    });

    /*点击确定按钮将所选商品添加至主表单*/
    function confirmDemoAdd() {
        /*循环所选商品数组中所有数据*/
        for (var i = 0; i < comBatchArrayObj.length; i++){
            /*是你啊小欻欻*/
            var ii = 1;

            /*主表单数组*/
            for(var j = 0; j <confirmDemoAddObj.length; j++){
                /*判断生产日期，产品批号，生产厂商是否相同(相同则累加数量)*/
                if(eval(comBatchArrayObj[i].salOrdDescProStartDate)==eval(confirmDemoAddObj[j].orsalOrdDescProStartDate)&&
                    comBatchArrayObj[i].salOrdDescProBatchNum==confirmDemoAddObj[j].orsalOrdDescProBatchNum&&
                    comBatchArrayObj[i].salOrdDescManufacturer==confirmDemoAddObj[j].orsalOrdDescManufacturer&&
                    comBatchArrayObj[i].salOrdId==confirmDemoAddObj[j].orsalOrdId){

                    confirmDemoAddObj[j].orsalOrdDescProNum = eval(confirmDemoAddObj[j].orsalOrdDescProNum) + eval(comBatchArrayObj[i].salOrdDescProNum);

                    ii = 0;
                    break;
                }

            }

            if(ii == 1){
                confirmDemoAddObj.push({
                    /*商品编号*/
                    orproId:comBatchArrayObj[i].productId,
                    /*商品名称*/
                    orproName:comBatchArrayObj[i].salOrdDescProName,
                    /*商品单位*/
                    orsalOrdDescUnit:comBatchArrayObj[i].salOrdDescUnit,
                    /*销售订单编号(原始单号)*/
                    orsalOrdId:comBatchArrayObj[i].salOrdId,
                    /*仓库编号*/
                    ordepotId:comBatchArrayObj[i].depotId,
                    /*产品规格*/
                    orproSize:comBatchArrayObj[i].proSize,
                    /*批准文号*/
                    proPostil:comBatchArrayObj[i].proPostil,
                    /*折扣率*/
                    depositRate:comBatchArrayObj[i].depositRate,
                    /*生产厂商*/
                    orsalOrdDescManufacturer:comBatchArrayObj[i].salOrdDescManufacturer,
                    /*商品单价*/
                    orsalOrdDescProPrice:comBatchArrayObj[i].salOrdDescProPrice,
                    /*商品数量*/
                    orsalRetDescProNum:comBatchArrayObj[i].salOrdDescProNum,
                    /*产品批号*/
                    orsalOrdDescProBatchNum:comBatchArrayObj[i].salOrdDescProBatchNum,
                    /*生产日期*/
                    orsalOrdDescProStartDate:comBatchArrayObj[i].salOrdDescProStartDate,
                    /*有效期至*/
                    orsalOrdDescProValidityDate:comBatchArrayObj[i].salOrdDescProValidityDate,

                });

            }

        }

        /*再次点击添加商品时清空所选商品表单信息*/
        comBatchArrayObj = [];

        /*表格重载*/
        table.reload('currentTableId', {
            data:confirmDemoAddObj
        });

        /* var index = parent.layer.getFrameIndex(window.name); //先得到当前iframe层的索引
         parent.layer.close(index); //再执行关闭*/

        /*关闭所有弹窗*/
        layer.closeAll();
    }

    /*根据仓库编号查询主表信息*/
    var depotIdAddTable = [];
    form.on('select(aihaos)',function (obj) {
        depotId = obj.value;
        /*每次执行清空一次*/
        depotIdAddTable =[]
        for (var i in confirmDemoAddObj){
            if(confirmDemoAddObj[i].ordepotId == depotId){
                depotIdAddTable.push({
                    /*商品编号*/
                    orproId:confirmDemoAddObj[i].orproId,
                    /*商品名称*/
                    orproName:confirmDemoAddObj[i].orproName,
                    /*商品单位*/
                    orsalOrdDescUnit:confirmDemoAddObj[i].orsalOrdDescUnit,
                    /*销售订单编号(原始单号)*/
                    orsalOrdId:confirmDemoAddObj[i].orsalOrdId,
                    /*仓库编号*/
                    ordepotId:confirmDemoAddObj[i].ordepotId,
                    /*产品规格*/
                    orproSize:confirmDemoAddObj[i].orproSize,
                    /*批准文号*/
                    proPostil:confirmDemoAddObj[i].proPostil,
                    /*折扣率*/
                    depositRate:confirmDemoAddObj[i].depositRate,
                    /*生产厂商*/
                    orsalOrdDescManufacturer:confirmDemoAddObj[i].orsalOrdDescManufacturer,
                    /*商品单价*/
                    orsalOrdDescProPrice:confirmDemoAddObj[i].orsalOrdDescProPrice,
                    /*商品数量*/
                    orsalRetDescProNum:confirmDemoAddObj[i].orsalRetDescProNum,
                    /*产品批号*/
                    orsalOrdDescProBatchNum:confirmDemoAddObj[i].orsalOrdDescProBatchNum,
                    /*生产日期*/
                    orsalOrdDescProStartDate:confirmDemoAddObj[i].orsalOrdDescProStartDate,
                    /*有效期至*/
                    orsalOrdDescProValidityDate:confirmDemoAddObj[i].orsalOrdDescProValidityDate,
                })

            }

        }

        for (var i in info){
            wholeNum = info.length;
            if(info[i].ordepotId == depotId ){
                depotIdAddTable.push({
                    /*商品编号*/
                    orproId:info[i].orproId,
                    /*商品名称*/
                    orproName:info[i].orproName,
                    /*商品单位*/
                    orsalOrdDescUnit:info[i].orsalOrdDescUnit,
                    /*销售订单编号(原始单号)*/
                    orsalOrdId:info[i].orsalOrdId,
                    /*仓库编号*/
                    ordepotId:info[i].ordepotId,
                    /*产品规格*/
                    orproSize:info[i].orproSize,
                    /*批准文号*/
                    proPostil:info[i].proPostil,
                    /*折扣率*/
                    depositRate:info[i].depositRate,
                    /*生产厂商*/
                    orsalOrdDescManufacturer:info[i].orsalOrdDescManufacturer,
                    /*商品单价*/
                    orsalOrdDescProPrice:info[i].orsalOrdDescProPrice,
                    /*商品数量*/
                    orsalRetDescProNum:info[i].orsalRetDescProNum,
                    /*产品批号*/
                    orsalOrdDescProBatchNum:info[i].orsalOrdDescProBatchNum,
                    /*生产日期*/
                    orsalOrdDescProStartDate:info[i].orsalOrdDescProStartDate,
                    /*有效期至*/
                    orsalOrdDescProValidityDate:info[i].orsalOrdDescProValidityDate,
                })
            }
        }

        table.reload('currentTableId',{
            data:depotIdAddTable
        });

        /*显示添加商品删除商品*/
        if (depotIdAddTable.length >= 0 && wholeNum > 0){
            $("#deleteBut").css({'display': 'none'});
            $("#addBut").css({'display': 'none'});
        }
    });

    /*点击整单退货跳转显示仓库与客户名称*/
    for(var i in info){
        wholeNum = info.length;
        $('#demo1').val(info[i].orcustName);
        $('#custId').val(info[i].orcustId);
    }


    function addDisabled() {
        if (confirmDemoAddObj.length <= 0 && wholeNum == 0) {
            /* 隐藏修改删除按钮 */
            $("#deleteBut").css({'display': 'none'});
            $('#demo1').attr("disabled",false);
            $('#deport').attr("disabled",true);
            form.render('select');
            /* 隐藏修改删除按钮 end */
        } else {
            /* 显示修改删除按钮 */
            $("#deleteBut").css({'display': 'inline-block'});
            $('#demo1').attr("disabled",true);
            $('#deport').attr("disabled",false);

            form.render('select');
            /* 显示修改删除按钮 end */
        }
    }

    if(wholeNum > 0){
        /*禁用客户按钮启用仓库按钮*/
        $("#deleteBut").css({'display': 'none'});
        $("#addBut").css({'display': 'none'});
        $('#demo1').attr("disabled",true);
        $('#deport').attr("disabled",true);
        form.render();
    }else {
        $("#deleteBut").css({'display': 'none'});
        $('#demo1').attr("disabled",false);
        $('#deport').attr("disabled",true);
        form.render();
    }

    /*传递至主表单*/
    $(document).on('click','#confirmDemoAddBut',function () {
        /*判断所选商品是否有数据*/
        if (comBatchArrayObj[0] != null){
            confirmDemoAdd();
        }else{
            layer.msg('请添加商品!');
        }

        /*再次添加时刷新所选商品表单*/
        table.reload('commoditydemoAdd',{
            data:comBatchArrayObj
        });

    })

    /*所选商品删除按钮*/
    $(document).on('click','#deleteDemoAddBut',function () {
        if(comBatchArrayObj[0]!= null){
            layer.confirm('是否确定删除?', function(index){

                /*获取选中数据在表单中的下标位置并删除*/
                comBatchArrayObj.splice(SelectedIndex,1);

                /*清空选中删除数据*/
                SelectedData = null;

                table.reload("commoditydemoAdd",{
                    data:comBatchArrayObj // 将新数据重新载入表格
                })

                layer.close(index);

            })
        }else {
            layer.msg('未添加商品!');
        }
    });

    /*所选商品取消按钮*/
    $(document).on('click','#outDemoAddBut',function () {
        /*所选商品表单为空直接退出*/
        if(comBatchArrayObj[0] == null){
            layer.closeAll();
            /*有数据提示是否退出*/
        }else {
            layer.open({
                type:0,
                title: "系统信息",
                area: ['340px', '230px'],
                content: "<div style='text-align:center;line-height: 100px;font-size:16px;'>所选商品还未保存，是否保存？</div>",
                btn: ['是', '否'],
                btn1:function(){
                    confirmDemoAdd();
                    /*再次添加时刷新所选商品表单*/
                    table.reload('commoditydemoAdd',{
                        data:comBatchArrayObj
                    });
                },
                btn2:function(){
                }
            })
        }
    })

    var tableList = [];

    /****************商品列表****************/
    $.ajax({
        url:"/showReturnInfo",
        success:function (data) {
            var dataTree = JSON.parse(data);
            /*树状图*/
            tree.render({
                elem:"#proListTree",
                data: dataTree,
                onlyIconControl: true,	//只能通过节点左侧图标来展开收缩
                click:function (obj) {
                    /*获取商品类别ID*/
                    var proTypeId = obj.data.id;
                    /*刷新右侧表单*/
                    table.reload('proListInfo',{
                        url:'/showReturnTree/'+proTypeId
                    })
                }
            })
        }
    })

    // 右侧商品列表信息
    table.render({
        elem: '#proListInfo'
        ,height: 366
        ,url : '/showReturnTree/0000'
        ,cols: [[ //表头
            {field: 'productId', title: '商品编号', width:100/*, fixed: 'left'*/}
            ,{field: 'salOrdDescProName', title: '商品名称', width:100}
            ,{field: 'salOrdDescUnit', title: '单位', width:100, sort: true}
            ,{field: 'salOrdDescProPrice', title: '预设售价', width: 110, sort: true}
            ,{field: 'salOrdDescProNum', title: '销售量', width: 100, sort: true}
            ,{field: 'salOrdDescManufacturer', title: '生产商', width: 100}
        ]],
    });



    /*退货信息新增至数据库*/
    $(document).on('click','#addReturnGood',function () {
        /*console.log(JSON.stringify(form.val('addSaleData')));*/
        if (depotIdAddTable.length == 0 && wholeNum <= 0 || confirmDemoAddObj == null) {

            if(confirmDemoAddObj.length != 0 && depotId == null){
                layer.open({
                    type: 0,
                    title: "系统信息",
                    area: ['300px', '230px'],
                    content: "<div style='text-align:center;line-height: 100px;font-size:16px;'>请选择收货仓库！</div>"
                })
            }else {
                layer.open({
                    type: 0,
                    title: "系统信息",
                    area: ['300px', '230px'],
                    content: "<div style='text-align:center;line-height: 100px;font-size:16px;'>未添加单据不能保存！</div>"
                });
            }
        } else {
            layer.open({
                type: 0,
                title: "系统信息",
                area: ['340px', '230px'],
                content: "<div style='text-align:center;line-height: 100px;font-size:16px;'>单据保存后不能再修改，是否确认保存！</div>",
                btn: ['确认', '取消'],
                btn1:function(index){
                    /*调用新增退货*/
                    addSaleObj();
                    //关闭弹出层
                    layer.close(index);

                    parent.layer.close(parent.tanchuchengIndex);

                    layer.msg('客户退货成功！',{time:500},function () {
                        location.href='sell_customerReturn.html';
                    });

                },
                btn2:function(){
                }
            });

        }

    });


    /*对数据库进行修改and 新增操作*/
    function addSaleObj() {
        var proSaleReturn = JSON.stringify(form.val('addSaleData'));
        var returnDate = $("input[name = 'salRetDate']").val();
        /*去掉数组中括号*/
        //var proSaleReturnDescArraybj = JSON.stringify(confirmDemoAddObj).replace('[','').replace(']','')

        var projectEnd = [];
        /*判断是否选择了仓库*/
        if(wholeNum == 0){
            projectEnd = depotIdAddTable;
        }else if(info.length > 0){
            projectEnd = info;
        }

        var proSaleReturnDesc = "";

        for ( var i in projectEnd ) {
            proSaleReturnDesc += JSON.stringify({
                /*销售退货明细编号*/
                salRetDescId:$('#RandomSingleNum').val()+i,
                /*销售退货编号*/
                salRetId:$('#RandomSingleNum').val(),
                /*退货商品数量*/
                salRetDescNum:projectEnd[i].orsalRetDescProNum,
                /*商品数量*/
                salRetDescProNum:projectEnd[i].orsalRetDescProNum,
                /*商品单价*/
                salRetDescProPrice:projectEnd[i].orsalOrdDescProPrice,
                /*商品名称*/
                salRetDescProName:projectEnd[i].orproName,
                /*产品批号*/
                salRetDescproBatchNum:projectEnd[i].orsalOrdDescProBatchNum,
                /*生产日期*/
                salRetDescProStartDate:dataTime(projectEnd[i].orsalOrdDescProStartDate),
                /*有效期*/
                salRetDescProValidityDate:dataTime(projectEnd[i].orsalOrdDescProValidityDate),
                /*单位*/
                salRetDescUnit:projectEnd[i].orsalOrdDescUnit,
                /*生产厂商*/
                salRetDescManufacturer:projectEnd[i].orsalOrdDescManufacturer,
                /*销售订单编号(原始单号)*/
                salRetDescOriginalNum:projectEnd[i].orsalOrdId,
                /*商品编号*/
                productId:projectEnd[i].orproId,
                /*仓库编号*/
                depotId:projectEnd[i].ordepotId,
                /*退货日期*/
                returnDate:returnDate,
            });

            console.log(proSaleReturnDesc)
            if (i != depotIdAddTable.length - 1 && depotIdAddTable.length > 1) {
                proSaleReturnDesc += ",";
            }
        }
        $.ajax({
            url:"/addSalesReturn/"+ proSaleReturn +"/"+proSaleReturnDesc,
            dataType : "json"
        });
    }
    /*对数据库进行修改and 新增操作 end*/

    /*所有单击选中数据表添加样式*/
    /*******************************单击时选中商品信息*******************************/
    /*所选商品列表添加样式*/
    table.on('row(commoditydemoAdd)', function(obj){
        /*选中所选商品单行数据*/
        SelectedData = obj.data;
        console.log(SelectedData)
        /*选中所选商品获取数据下标位置*/
        SelectedIndex = obj.tr.attr('data-index');
        obj.tr.addClass('layui-bg-green').siblings().removeClass('layui-bg-green');
    });

    /*添加商品清单添加样式*/
    table.on('row(commoditydemo8)', function(obj){
        /*选中清单单行数据*/
        salOrdData = obj.data;

        obj.tr.addClass('layui-bg-green').siblings().removeClass('layui-bg-green');
    });

    /*主表单添加样式*/
    table.on('row(mportExpor)', function(obj){
        /*选中清单单行数据*/
        mainTableData = obj.data;
        /*主表商品获取数据下标位置*/
        mainTableIndex = obj.tr.attr('data-index');
        console.log(mainTableIndex)
        obj.tr.addClass('layui-bg-green').siblings().removeClass('layui-bg-green');
    });

    /*商品售价列表*/
    table.render({
        elem: '#priceTabulationTable',
        url: '../../api/price.json',
        /*data:[],*/
        height:300,
        width:308,
        toolbar:'#priceBtn',
        cols: [[
            {field: 'tabulation', width: 110, title: '售价列表'},
            {field: 'price', width: 80, title: '售价',sort: true}
        ]],
        skin: 'line'
    });

    /*商品售价列表(选中单行修改信息)*/
    table.on('row(priceTabulationTable)', function(obj){
        /*商品售价列表添加样式*/
        obj.tr.addClass('layui-bg-green').siblings().removeClass('layui-bg-green');
        var rowdata = obj.data;
    });
    /*修改商品售价弹窗*/
    $('#priceSelect').on('click',function(){
        layer.open({
            type: 1,
            title: '<h2 style="color: black;font-weight: bold;">商品售价列表<h2>',
            scrollbar: false,
            area: ['25%', '50%'],/*宽，长*/
            /*btn:['是','否'],*/
            content: $('#priceTabulation')
        });
    });

    /*双击获取售价信息*/
    table.on('rowDouble(priceTabulationTable)',function(obj){
        console.log(obj);
    });


    /*修改商品售价列表*/
    table.on('toolbar(priceTabulationTable)',function(obj){
        switch(obj.event){
            case 'update':
                updatePrice();
                break;
        }
    })

    /*售价列表(修改弹窗)*/
    function updatePrice(){
        layer.open({
            type: 1,
            title: '<h2 style="color: black;font-weight: bold;">修改售价<h2>',
            scrollbar: false,
            area: ['22%', '39%'],/*宽，长*/
            btn:['是','否'],
            content: $('#updatePriceTab')
        });
    }

    /*退货数量提示框*/
    function returnNumDeficiency() {
        layer.open({
            type: 0,
            title: "提示信息",
            area: ['340px', '230px'],
            content: "<div style='text-align:center;line-height: 100px;font-size:16px;'>当前销售商品可退货数量不足</div>",
            btn: ['确认', '取消'],
            bun1:function(index){
                close(index);
            },
            btn2:function(){
            }
        })
    }
});